package com.hsy.authorization.mvp.ui.activity;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import butterknife.BindView;
import com.hsy.authorization.R;
import com.hsy.authorization.mvp.ui.adapter.MainAuthorizeAdapter;
import com.hsy.authorization.mvp.ui.fragment.AuthorizeEdListFragment;
import com.hsy.authorization.mvp.ui.fragment.AuthorizeUnListFragment;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.base.BaseFragment;
import com.jess.arms.di.component.AppComponent;

import java.util.ArrayList;
import java.util.List;

public class MainAuthorizeActivity extends BaseActivity {
    @BindView(R.id.authorize_main_tablayout)
    TabLayout authorizeMainTablayout;
    @BindView(R.id.authorize_main_viewpager)
    ViewPager authorizeMainViewpager;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {

    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_main_authorize;
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        String[] titles = getResources().getStringArray(R.array.authorize_list_tabtitle);
        for (String title : titles)
            authorizeMainTablayout.addTab(authorizeMainTablayout.newTab().setText(title));
        List<BaseFragment> fragments = new ArrayList<>();
        fragments.add(AuthorizeUnListFragment.newInstance());
        fragments.add(AuthorizeEdListFragment.newInstance());
        MainAuthorizeAdapter adapter = new MainAuthorizeAdapter(getSupportFragmentManager(), fragments);
        adapter.setTitles(titles);
        authorizeMainViewpager.setAdapter(adapter);
        authorizeMainTablayout.setupWithViewPager(authorizeMainViewpager);
        authorizeMainTablayout.setTabsFromPagerAdapter(adapter);
    }


}
